<template>
  <div>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell
        v-for="item in list"
        :key="item.filmId"
        @click="handelRouter(item.filmId)"
      >
        <div class="varCellitem">
          <img :src="item.poster" alt="" />
          <div class="info">
            <div class="title">
              {{ item.name }} <em>{{ item.item.name }}</em>
            </div>
            <div>
              上映时间：<span>{{ item.premiereAt | premiereAtHandle }}</span>
            </div>
            <div class="actors">主演：{{ item.actors | actorsHandle }}</div>
            <div>{{ item.nation }} | {{ item.runtime }}分钟</div>
          </div>
        </div>
      </van-cell>
    </van-list>
  </div>
</template>

<script>
import Vue from 'vue'
import http from '@/util/http.js'
import { mapState } from 'vuex'
// 导入时间小模块
import moment from 'moment'
// 挂载过滤
Vue.filter('premiereAtHandle', (data) => {
  return moment(data * 1000).format('YYYY-MM-DD')
})
Vue.filter('actorsHandle', (data) => {
  if (!data) return '暂无主演'
  return data.map((item) => item.name).join(' ')
})
export default {
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      index: 1
    }
  },
  computed: {
    ...mapState(['cityId'])
  },
  methods: {
    handelRouter (id) {
      this.$router.push(`/listDetails/${id}`)
    },
    onLoad () {
      // 异步更新数据
      http({
        url: `/gateway?cityId=${this.cityId}&pageNum=${this
          .index++}&pageSize=10&type=2&k=8334197`,
        headers: {
          'X-Host': 'mall.film-ticket.film.list'
        }
      }).then((res) => {
        console.log(res.data.data)
        this.list.push(...res.data.data.films)
        // 数据全部加载完成
        if (this.list.length >= res.data.data.total) {
          this.finished = true
        }
      })

      // 加载状态结束
      this.loading = false

      // }, 1000);
    }
  }
}
</script>

<style lang="scss" scoped>
$textColor: #797d82;
$themeColor: #ffb232;
.van-list {
  background: #fff;
  margin-top: 10px;
}
.varCellitem {
  display: flex;
  height: 7.75rem;
  align-items: center;
  font-size: 13px;
  line-height: 1.5;
  img {
    width: 4.125rem;
    height: 5.8125rem;
  }
  .info {
    width: 14rem;
    height: 5.125rem;
    padding: 0 0.625rem;
    color: $textColor;
    span {
      color: $themeColor;
    }
  }
  a {
    width: 3.4375rem;
    height: 1.5625rem;
    border: 0.0625rem solid $themeColor;
    color: $themeColor;
    line-height: 1.5625rem;
    text-align: center;
    text-decoration: none;
  }
  .title {
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 16px;
    color: #333;
    em {
      display: inline-block;
      height: 14px;
      background: #d2d6dc;
      color: #fff;
      font-style: normal;
      font-size: 12px;
      line-height: 14px;
      padding: 0 3px;
      border-radius: 2px;
    }
  }
  .actors {
    width: 100%;
    overflow: hiden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
</style>
